package com.xiehua.task;

import com.xiehua.common.config.ApplicationContextRegister;
import com.xiehua.task.server.ServerApp;
import com.xiehua.task.service.impl.ConfigClientServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

public class ApplicationStartedEventListener implements ApplicationListener<ContextRefreshedEvent> {

    private Logger logger = LoggerFactory.getLogger(ApplicationStartedEventListener.class);

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        logger.info("==>>容器初始化完毕<<==");
        try {
            //load some config item from db
            ConfigClientServiceImpl configClientService = ApplicationContextRegister.getBean(ConfigClientServiceImpl.class);
            configClientService.updateConfig();
            //start task server
            String[] args = {};
            ServerApp.main(args);
        } catch (Exception e) {
            logger.error("任务调取器启动失败",e);
        }

    }
}
